﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>员工管理</title>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../css/Jqbox.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery-1.5.2.min.js" type="text/javascript"></script>
    <script src="../js/ligerui.min.js" type="text/javascript"></script>
    <script src="../Js/jquery.dialog.js" type="text/javascript"></script>
    <script src="../Js/conmon.js" type="text/javascript"></script>
    <script type="text/javascript">
        var $grid;
        var $selectRow = null;
        var treepanel = null;
        var height = 0;
        var menu = null;
        var tree = null;

        $(function () {
            // 绑定角色为空
            $("#Rid").val("-1");

            $("#layout1").ligerLayout({ leftWidth: 190 });
            height = $(".l-layout-center").height();

            //显示gride
            $grid = $("#maingrid").ligerGrid({
                columns: [
               { display: '序号', align: 'left', width: 40, type: 'int', isSort: false,
                   render: function (item, i) {
                       i = i + 1;
                       return i;
                   }
               },
                { display: '姓名', name: 'M_NAME', align: 'left', width: 80 },
                { display: '工号', name: 'M_CODE', width: 100 },
                { display: '性别', name: 'M_SEX', width: 35,
                    render: function (item) {
                        if (item.M_SEX == 0) return "女";
                        else return "男";
                    }
                },
                { display: '电话', name: 'M_PHONE', width: 90 },
                { display: '区域', name: 'A_NAME', width: 90 },
                { display: '职务', name: 'R_NAME', width: 120 },
                { display: '注册时间', name: 'M_DATE', dateFormat: "yyyy-MM-dd", width: 80 },
                { display: '状态', name: 'J_STATUS', isSort: false, width: 80,
                    render: function (item) {
                        if (item.M_STATUS == 0) return "√";
                        else return "×";
                    }
                },
                 { display: '停/启用', name: 'M_STATUS', isSort: false, width: 50,
                     render: function (item) {
                         if (item.M_STATUS == 1)
                             return "<a   onclick='StopItem(" + item.M_ID + ",&quot;" + item.M_STATUS + "&quot;)' href='javascript:' >启用</a>";
                         else
                             return "<a   onclick='StopItem(" + item.M_ID + ",&quot;" + item.M_STATUS + "&quot;)' href='javascript:' >停用</a>";
                     }
                 },
                  { display: '查看考试记录', name: 'M_ID', isSort: false, width: 120,
                      render: function (item) {
                          var result = "<a   onclick='HistoryGrid(" + item.M_ID + ", \"" + item.M_NAME + "\")' href='javascript:' >表格</a>&nbsp;&nbsp;";
                          result += "<a   onclick='HistoryChart(" + item.M_ID + ", \"" + item.M_NAME + "\")' href='javascript:' >图表</a>";

                          return result;
                      }
                  }
                ],
                parms: [{ name: 'userName', value: $("#txtUserName").val() }, { name: 'status', value: $("#lstStatus").val() }, { name: 'aid', value: '-1' }, { name: 'rid', value: '-1' }, { name: 'fileName', value: 'UserTable'}],
                dataAction: 'server', pageSize: 20,
                url: '../WebServer/EmpManage.ashx?Action=AreaRolUserList',
                sortName: 'M_NAME',
                width: "100%", height: "100%",
                onDblClickRow: function (data, rowindex, rowobj) {
                    $selectRow = data;
                    ShowDialog("sysManage/EditeEmp.htm", "编辑", 450, 225);
                }
            });

            $("#txtUserName").ligerTextBox();
            loadTree();
        });

        function loadTree() {
            tree = $("#Orgtree").ligerTree({
                checkbox: false,
                slide: false,
                nodeWidth: 100,
                url: "../WebServer/EmpManage.ashx?Action=AreRoleTree&rnd=" + Math.random(),
                onSelect: function (node) {
                        $("#Aid").val(node.data.areid);
                        $("#Rid").val(node.data.value);
                        $("#txtUserName").val("");
                        $("#lstStatus").val("-1");
                        loadGrid();
                }
            });

            $("#treePanel").height(height - 24);
        }

        function Additemclick() {

            var role = $("#Rid").val();

            if (parseInt(role) == -1) {
                showErrorTip("请选定职务后添再加员工");
                return;
            }

            ShowDialog("sysManage/AddEmp.htm", "添加员工", 280, 400);
        }


        function HistoryGrid(userid, username) {
            parent.window.jmp_member_exam(userid, username);
        }

        function HistoryChart(userid, username) {
            this.user = { id: userid, username: username };
            ShowDialog("sysManage/userexamchart.htm", username+ " - 考试记录图表", 750, 400);
        }


        function Search() {
            var node = tree.getSelected();
            if (node == null) {
                $("#Aid").val("-1");
                $("#Rid").val("-1");
            }
            loadGrid();
        }


        function Excel() {
            //页面导出
            var url = "../WebServer/DownloadExcel.ashx?Action=UesrList"
                    + "&userName=" + $("#txtUserName").val()
                    + "&status=" + $("#lstStatus").val()
                    + "&aid=" + $("#Aid").val()
                    + "&rid=" + $("#Rid").val();
            window.open(url, "_blank");
        }


        function loadGrid() {
            if (!$grid) return;
            $("tbody > tr", $grid.gridbody).each(function () {
                $(this).remove();
            });
            $grid.setOptions({ parms: [
                                { name: 'userName', value: $("#txtUserName").val() },
                                { name: 'status', value: $("#lstStatus").val() },
                                { name: 'aid', value: $("#Aid").val() },
                                { name: 'rid', value: $("#Rid").val() },
                                { name: 'fileName', value: 'UserTable' }
                               ], newPage: 1, Rows: [], Total: 0 
                       });   //设置数据参数

            $grid.loadData(true); //加载数据
            closeDialog();
        }
        var $UpdateItem = new Object();

        function StopItem(id, status) {
            $("body").mask("数据处理中，请稍候......");

            $.getJSON('../WebServer/EmpManage.ashx?Action=StopItem', { userid: id, status: status }, function (data) {
                $("body").unmask();
                if (data.IsSuccess == 1) {
                    showAlertOk("成功");

                    loadGrid();
                } else {
                    showErrorTip(data.Msg);
                }
            });
        }

        function RuserPwd(id, name) {
            $UpdateItem.id = id;
            $UpdateItem.name = name;
            ShowDialog("sysManage/UpdatePwd.htm", "修改密码", 270, 210);
        }
        
    </script>
    <style type="text/css">
        body
        {
            padding: 5px;
            margin: 0;
            padding-bottom: 15px;
        }
        #layout1
        {
            width: 100%;
            margin: 0;
            padding: 0;
        }
        .l-page-top
        {
            height: 80px;
            background: #f8f8f8;
            margin-bottom: 3px;
        }
        h4
        {
            margin: 20px;
        }
        #menu1, .l-menu-shadow
        {
            top: 30px;
            left: 50px;
        }
        #menu1
        {
            width: 200px;
        }
    </style>
</head>
<body style="padding: 10px">
    <div id="layout1">
        <div position="left" title="" style="overflow: auto;">
            <div id="treePanel">
                <ul id="Orgtree">
                </ul>
            </div>
        </div>
        <!-- end-->
        <div position="center" title="">
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="65">员工姓名:</td>
                    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="80"><input id="txtUserName" type="text" /></td>
                    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="65">员工状态:</td>
                    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="80">
                        <select id="lstStatus">
                            <option value="-1" title="全部" selected="selected">全部</option>
                            <option value="0">启用</option>
                            <option value="1">停用</option>
                        </select>
                    </td>
                    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="80"><a class="l-button" style="width: 60px; float: left; margin-left: 10px;" onclick="Search()">查寻</a></td>
                    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="80"><a class="l-button" style="width: 60px; float: left; margin-left: 10px;" onclick="Additemclick()">添加员工</a></td>
                    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;"><a class="l-button" style="width: 60px; float: left; margin-left: 10px;" onclick="Excel()">导出Excel</a></td>
                </tr>
            </table>

            <div id="maingrid">
            </div>
        </div>
    </div>
    <a id="ExdcleGo" href=""></a>
    <input type="hidden" id="Aid" value="-1" />
    <input type="hidden" id="Rid" value="-1" />
</body>
</html>
